package cn.aigoubuy.web.filter;

import cn.aigoubuy.domain.User;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter(urlPatterns = {"/jsp/order_info.jsp","/jsp/cart.jsp", "/jsp/order_list.jsp","/orderServlet","/cartServlet"})
public class PriviledgeFilter extends HttpFilter {
    @Override
    protected void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws IOException, ServletException {
        User loginUser = (User) req.getSession().getAttribute("loginUser");
        if (loginUser == null) {
            req.setAttribute("msg", "您还没有登录！没有权限访问！");
            req.getRequestDispatcher("/jsp/info.jsp").forward(req, res);
            return;
        }
        chain.doFilter(req, res);
    }
}